package ferp.android.dialogs;

import android.content.Context;
import android.text.InputType;
import android.view.View;
import android.view.WindowManager;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import ferp.android.GUI;
import ferp.android.R;

/**
 * User: olegs
 * Date: 2/6/13 11:03 AM
 */
public class ImportProfileDialog extends Dialog
{
  public interface Listener
  {
    void onSaveClick(int requestCode, String value, boolean fromCurrentPosition);
  }

  public ImportProfileDialog(Context context, Listener listener, int requestCode)
  {
    super(context, R.layout.dialog_import_profile, R.string.import_profile);

    // set listener
    this.listener = listener;
    this.requestCode = requestCode;

    // always show keyboard
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

    // resolve widgets
    editText = (EditText)findViewById(R.id.dlg_import_profile_edit_text);
    editText.setTypeface(GUI.Font.BOLD);
    editText.setInputType(InputType.TYPE_CLASS_NUMBER);
    editText.setText("");

    checkBox = (CheckBox)findViewById(R.id.dlg_import_profile_check_box);
    checkBox.setTypeface(GUI.Font.BOLD);
    checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
    {
      @Override
      public void onCheckedChanged(CompoundButton compoundButton, boolean b)
      {
        checkBox.setText(b ? R.string.import_profile_from_current_position : R.string.import_profile_from_initial_position);
      }
    });

    // set 'save' button listener
    resolveButton(R.id.dlg_element_footer_button, R.string.save).setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View view)
      {
        ImportProfileDialog.this.listener.onSaveClick(ImportProfileDialog.this.requestCode, editText.getText().toString().trim(), checkBox.isChecked());
      }
    });
  }

  // listener
  private final Listener listener;
  // request code
  private final int requestCode;

  // widgets
  private final EditText editText;
  private CheckBox checkBox;
}
